﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using PSE.Framework.ErrorLogging;
using Sinacor.Infra.Common.ErrorLogging;

namespace Sinacor.Infra.Service.ErrorLogging
{
    public class SecurityTokenServiceEnvironmentCollector : SinacorEnvironmentCollector
    {
        protected override PSE.Framework.ErrorLogging.EnvironmentData CreateEnvironmentData()
        {
            return new SecurityTokenServiceEnvironmentData();
        }

        protected override string GetVersion()
        {
            // Não disponível
            return "-";
        }

        public override PSE.Framework.ErrorLogging.EnvironmentData Collect(Dictionary<string, object> extensionData)
        {
            EnvironmentData environmentData = base.Collect(extensionData) as EnvironmentData;

            if (environmentData != null &&
                environmentData is SecurityTokenServiceEnvironmentData)
            {
                SecurityTokenServiceEnvironmentData securityTokenServiceEnvironmentData = (SecurityTokenServiceEnvironmentData)environmentData;

                try
                {
                    if (extensionData != null && extensionData.ContainsKey("SinacorUserName"))
                        securityTokenServiceEnvironmentData.SinacorUserName = this.GetData<string>(() => (string)extensionData["SinacorUserName"], "SinacorUserName", environmentData);
                }
                catch (Exception ex)
                {
                    securityTokenServiceEnvironmentData = (SecurityTokenServiceEnvironmentData)HandleException(securityTokenServiceEnvironmentData, ex);
                }
            }

            return environmentData;
        }
    }
}
